<?php
/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * date: 2021-07-27 14:55:18
 * @LastEditors: Sam
 * @LastEditTime: 2021-12-03 20:12:35
 */

namespace app\admin\model;
use think\Model;


/**
 * 砍价 model
 * Class Seckill
 * @package app\admin\model\user
 */
class SeckillDetail extends BaseModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'seckill_detail';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    public function user(){
        return $this->belongsTo(User::class,'uid')->bind(['nickname','avatar']);
    }



    public function activity(){
        return $this->belongsTo(Seckill::class,'aid')->bind(['title','start_time','end_time','stock']);
    }


    /**
     * 生成订单号

     * @return void
     * @author Sam
     * date 2020-11-18
     */
    public  static function create_order_no($pre = 'OD')
    {
        $order_sn =  $pre.date('Y').date('m').date('d').rand(100000, 999999);
        while (1) {
            $count = self::where('order_sn',$order_sn)->count();
            if ($count <= 0) {
                break;
            }
            $order_sn = rand(100000, 999999);
        }
        return $order_sn;
    }
}